#include <2025Linux.h>
int DFSprint(char *path,int depth);
int main(int argc, char *argv[]){
    // ./03_mytree dir1
    ARGS_CHECK(argc,2);
    printf("%s\n", argv[1]);
    DFSprint(argv[1],1);
}
int DFSprint(char *path, int depth){
    // 不调用chdir，用路径拼接来取代
    DIR * dirp = opendir(path);
    ERROR_CHECK(dirp,NULL,"opendir"); //只要用了ERROR_CHECK宏，就要返回int
    struct dirent * direntp;
    char newpath[2048] = {0}; //用来存放孩子的路径
    while((direntp = readdir(dirp)) != NULL){
        if(strcmp(direntp->d_name,".") == 0 ||
           strcmp(direntp->d_name,"..") == 0){
            continue;//跳过本次循环体
        }
        for(int i = 0; i < depth; ++i){
            printf("── ");
        }
        printf(" %s\n",direntp->d_name);
        //判断文件的类型 发现是目录
        if(direntp->d_type == DT_DIR){
            sprintf(newpath,"%s/%s",path,direntp->d_name);
            DFSprint(newpath,depth+1); // 父亲的路径/孩子的文件名
        }
    }
    closedir(dirp);
    return 0;
}
